package net.UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Receiver {
    public static void main(String[] args) throws Exception {
        DatagramSocket datagramSocket = new DatagramSocket(6666);
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
            datagramSocket.receive(packet);
            String s = new String(bytes, 0, packet.getLength());
            int port = packet.getPort();
            System.out.println("收到的数据是"+s+"ip:"+port);
            System.out.println("----------------------");
        }
    }
}
